import axios from 'axios';
import {getCookie} from './index'
import { Message } from 'element-ui';


const request = axios.create({
    timeout: 3000
})

// 请求拦截
request.interceptors.request.use(config => {
    const token = getCookie();

    if(token) {
        config.headers.authorization = token;
    }

    return config
})


// 响应拦截
request.interceptors.response.use(config => {
    return config.data
}, err => {
    // 将错误信息展示到页面中
    Message.error(err.response.data.msg)
    
    return Promise.reject(err)
})

export default request;